﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FacturIT.BLL.Model.Helper
{
    public class CompareHelper
    {

        /// <summary>
        /// ori: 1234
        /// containing:34
        /// </summary>
        /// <param name="original">dbvalue</param>
        /// <param name="containingValue">value that has to contain</param>
        /// <returns></returns>
        internal static bool ContainsIgnoreCase(string original, string containingValue)
        {
            return original != null ? original.IndexOf(containingValue, StringComparison.InvariantCultureIgnoreCase) >= 0:false;
        }

        internal static bool EqualsIgnoreCase(string original, string containingValue)
        {
            return original != null ? original.ToLower().Equals(containingValue.ToLower()) : false;
        }

        internal static bool Between(DateTime dateToCompare, DateTime lower, DateTime upper)
        {
            return lower <= dateToCompare && dateToCompare <= upper;
        }
        internal static bool Between(DateTime? dateToCompare, DateTime? lower, DateTime? upper)
        {
            return dateToCompare.HasValue && lower.HasValue && upper.HasValue ? Between(dateToCompare.Value, lower.Value, upper.Value) : false;
        }
        internal static bool Between(DateTime? dateToCompare, DateTime lower, DateTime upper)
        {
            return dateToCompare.HasValue ? Between(dateToCompare.Value, lower, upper) : false;
        }

        internal static bool Between(int dateToCompare, int lower, int upper)
        {
            return lower <= dateToCompare && dateToCompare <= upper;
        }
        internal static bool Between(int? dateToCompare, int? lower, int? upper)
        {
            return dateToCompare.HasValue && lower.HasValue && upper.HasValue ? Between(dateToCompare.Value, lower.Value, upper.Value) : false;
        }
        internal static bool Between(int? dateToCompare, int lower, int upper)
        {
            return dateToCompare.HasValue ? Between(dateToCompare.Value, lower, upper) : false;
        }

        internal static bool In(int original, int[] possibleValues)
        {
            return possibleValues.Contains(original);
        }
        internal static bool In(int? original, int[] possibleValues)
        {
            return original.HasValue ? In(original.Value,possibleValues) : false;
        }
        internal static bool In(int original, List<int> possibleValues)
        {
            return In(original, possibleValues.ToArray());
        }
        internal static bool In(int? original, List<int> possibleValues)
        {
            return In(original.Value, possibleValues.ToArray());
        }

        internal static bool Equals(bool original, bool toComapair)
        {
            return original == toComapair;
        }
        internal static bool Equals(bool? original, bool toComapair)
        {
            return original.HasValue ? Equals(original.Value, toComapair) : false;
        }
        internal static bool Equals(bool? original, bool? toComapair)
        {
            return original.HasValue && toComapair.HasValue? Equals(original.Value, toComapair.Value) : false;
        }

        internal static bool Equals(int original, int toCompair)
        {
            return original == toCompair;
        }
        internal static bool Equals(int? original, int toCompair)
        {
            return original.HasValue ? Equals(original.Value, toCompair) : false;
        }
        internal static bool Equals(int? original, int? toCompair)
        {
            return original.HasValue && toCompair.HasValue ? Equals(original.Value, toCompair.Value) : false;
        }

        
    }
}
